//
//  InputToolsV.m
//  MGameTribe
//
//  Created by 杨敏 on 13-12-11.
//  Copyright (c) 2013年 YangMin. All rights reserved.
//

#import "InputToolsV.h"
#import "ConstantHeader.h"
#import "Tool.h"

@interface InputToolsV()


@end

@implementation InputToolsV

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor=[UIColor clearColor];
        
        self.topV=[[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame)/2)];
        _topV.backgroundColor=[UIColor clearColor];        
        [self addSubview:_topV];
        
        
        self.bottomV=[[UIView alloc]initWithFrame:CGRectMake(0, GetEndYWithView(_topV), CGRectGetWidth(self.frame), CGRectGetHeight(self.frame)/2)];
        _bottomV.backgroundColor=[UIColor whiteColor];
        [self addSubview:_bottomV];
        
        UIImage *sepaLineImg=ImageWithName(@"line_cellSeparat", @"png",NO);
        UIImageView *textSepaLineV=[[UIImageView alloc]initWithImage:sepaLineImg];
        textSepaLineV.frame=CGRectMake(0, 0, CGRectGetWidth(_bottomV.frame), 0.5);
        [_bottomV addSubview:textSepaLineV];
        
        UIImage *bottomImg=ResizeImage(ImageWithName(@"bg_toolBar_PubInput", @"png", NO), 0, 0, 31, 1);
        self.bottomBgV=[[UIImageView alloc]initWithImage:bottomImg];
        _bottomBgV.frame=_bottomV.bounds;
        [_bottomV addSubview:_bottomBgV];
        
        
        
        self.numOfTextLb=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 100, 21)];
        _numOfTextLb.font=[UIFont systemFontOfSize:FontSize_DefaultListTip];
        _numOfTextLb.backgroundColor=[UIColor clearColor];
        FitLableHeightWithLabel(_numOfTextLb);
        _numOfTextLb.textColor=[UIColor lightGrayColor];
        [_topV addSubview:_numOfTextLb];
        
        CGFloat width_player =80;
        
        self.playerV=[[AudioPlayerV alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.frame)-10-width_player, (CGRectGetHeight(_topV.frame)-Height_AudioPlayerV)/2, width_player, Height_AudioPlayerV)];
        [_topV addSubview:_playerV];
        CGRectSetCenterY(_numOfTextLb,_playerV.center.y+2);
//
//        UIImage *cameraImg_norm=ImageWithName(@"btn_publish_openCamera_norm", @"png", NO);
//        UIImage *cameraImg_high=ImageWithName(@"btn_publish_openCamera_high", @"png", NO);
//        UIImage *albumImg_norm=ImageWithName(@"btn_publish_openAlbum_norm", @"png", NO);
//        UIImage *albumImg_high=ImageWithName(@"btn_publish_openAlbum_high", @"png", NO);
//        CGFloat bottomBtnGap=(CGRectGetWidth(_bottomV.frame)-5*cameraImg_high.size.width)/6;
        UIImage *cameraImg_norm=ImageWithName(@"btn_publish_openCamera", @"png", NO);
        UIImage *albumImg_norm=ImageWithName(@"btn_publish_openAlbum", @"png", NO);
        CGFloat bottomBtnGap=(CGRectGetWidth(_bottomV.frame)-5*cameraImg_norm.size.width)/6;
        
        //相机
        self.cameraBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _cameraBtn.frame=CGRectMake(bottomBtnGap, (CGRectGetHeight(_bottomV.frame)-cameraImg_norm.size.height)/2, cameraImg_norm.size.width, cameraImg_norm.size.height);
        [_cameraBtn setBackgroundImage:cameraImg_norm forState:UIControlStateNormal];
//        [_cameraBtn setBackgroundImage:cameraImg_high forState:UIControlStateHighlighted];
        [_bottomV addSubview:_cameraBtn];
        //相册
        self.albumBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _albumBtn.frame=CGRectMake(GetEndYWithView(_cameraBtn)+bottomBtnGap, GetYWithView(_cameraBtn), cameraImg_norm.size.width, cameraImg_norm.size.height);
        [_albumBtn setBackgroundImage:albumImg_norm forState:UIControlStateNormal];
//        [_albumBtn setBackgroundImage:albumImg_high forState:UIControlStateHighlighted];
        [_bottomV addSubview:_albumBtn];
        
        //表情
        UIImage *emojiImg_norm=ImageWithName(@"btn_publish_openEmoji", @"png", NO);
        //UIImage *emojiImg_high=ImageWithName(@"btn_publish_openEmoji_high", @"png", NO);

        UIImage *keyBoardImg_norm=ImageWithName(@"btn_publish_openKeyBoard", @"png", NO);
        //UIImage *keyBoardImg_high=ImageWithName(@"btn_publish_openKeyBoard_high", @"png", NO);
        
        self.emojiBtn=[DoubleFaceButton buttonWithType:UIButtonTypeCustom];
        _emojiBtn.frame=CGRectMake(GetEndXWithView(_albumBtn)+bottomBtnGap, GetYWithView(_albumBtn), emojiImg_norm.size.width, emojiImg_norm.size.height);
        _emojiBtn.faceOne_norm=emojiImg_norm;
        //_emojiBtn.faceOne_high=emojiImg_high;
        _emojiBtn.faceTwo_norm=keyBoardImg_norm;
        //_emojiBtn.faceTwo_high=keyBoardImg_high;
        [_emojiBtn showBacgroundImageWith:0];
        [_bottomV addSubview:_emojiBtn];
//        //声音
//        UIImage *audioImg_norm=ImageWithName(@"tip_audio_norm", @"png", NO);
//        UIImage *audioImg_high=ImageWithName(@"tip_audio_high", @"png", NO);
//        self.audioBtn=[DoubleFaceButton buttonWithType:UIButtonTypeCustom];
//        _audioBtn.frame=CGRectMake(GetEndXWithView(_emojiBtn)+bottomBtnGap, GetYWithView(_albumBtn), CGRectGetWidth(_cameraBtn.frame), CGRectGetHeight(_cameraBtn.frame));
//        _audioBtn.faceOne_norm=audioImg_norm;
//        _audioBtn.faceOne_high=audioImg_high;
//        _audioBtn.faceTwo_norm=keyBoardImg_norm;
//        _audioBtn.faceTwo_high=keyBoardImg_high;
//        [_audioBtn showBacgroundImageWith:0];
//        [_bottomV addSubview:_audioBtn];

        UIImage *hideImg_up=ImageWithName(@"btn_hideInputBoard_up", @"png", NO);
        UIImage *hideImg_down=ImageWithName(@"btn_hideInputBoard_dowm", @"png", NO);
        self.hideBtn=[DoubleFaceButton buttonWithType:UIButtonTypeCustom];
        _hideBtn.frame=CGRectMake(CGRectGetWidth(_bottomV.frame) - CGRectGetWidth(_cameraBtn.frame) - UF(40), GetYWithView(_albumBtn) + UF(7), hideImg_up.size.width, hideImg_up.size.height);
        _hideBtn.faceOne_norm=hideImg_up;
        _hideBtn.faceTwo_norm=hideImg_down;
        [_hideBtn showBacgroundImageWith:0];
        [_bottomV addSubview:_hideBtn];
        
        
        CGRectSetCenterX(_playerV, _audioBtn.center.x);
        
        UIImageView *line =[[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(_bottomV.frame) - 0.5, kScreenWidth, 0.5)];
        line.backgroundColor = [UIColor lightGrayColor];
        [_bottomV addSubview:line];
    }
    return self;
}
-(void)setShowAudio:(BOOL)showAudio{
    _showAudio=showAudio;
    UIImage *cameraImg_high=ImageWithName(@"btn_publish_openCamera_high", @"png", NO);

    CGFloat bottomBtnGap=0;

    if (_showAudio) {
        bottomBtnGap=(CGRectGetWidth(_bottomV.frame)-5*cameraImg_high.size.width)/6;
        CGRectSetX(_cameraBtn, (CGRectGetWidth(_bottomV.frame)-bottomBtnGap*5-cameraImg_high.size.width*6)/2);
    }
    else{
        bottomBtnGap=(CGRectGetWidth(_bottomV.frame)-4*cameraImg_high.size.width)/5;
        CGRectSetX(_cameraBtn, (CGRectGetWidth(_bottomV.frame)-bottomBtnGap*3-cameraImg_high.size.width*4)/2);
    }
    
    CGRectSetX(_albumBtn, GetEndXWithView(_cameraBtn)+bottomBtnGap);
    CGRectSetX(_emojiBtn,GetEndXWithView(_albumBtn)+bottomBtnGap);
    CGRectSetX(_audioBtn, GetEndXWithView(_emojiBtn)+bottomBtnGap);
    
    _audioBtn.hidden=!showAudio;
    
    //CGRectSetX(_hideBtn, GetEndXWithView((_audioBtn.hidden?_emojiBtn:_audioBtn))+bottomBtnGap);

}


@end
